package com.woniu.controller.contemtService;

import com.github.pagehelper.PageInfo;
import com.woniu.model.contentMService.entity.Information;
import com.woniu.model.gh.common.Result;
import com.woniu.service.contentService.IInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 咨询部 前端控制器
 * </p>
 *
 * @author 作者
 * @since 2023-10-20
 */
@RestController
@RequestMapping("/information")
public class InformationController {

    @Autowired
    private IInformationService iInformationService;

    @GetMapping("/findAll")
    public Result<List<Information>> findAll() {
        List<Information> list = iInformationService.list();
        return Result.ok(list);
    }

    /**
     * 条件分页查询
     */
    @PostMapping("/findByPage")
    public Result<PageInfo<Information>> findByPage(@RequestBody Map<String, Object> condition) {
        PageInfo<Information> pageInfo = iInformationService.findByPage(condition);
        return Result.ok(pageInfo);
    }

    @GetMapping("/findById")//查看详情
    public Result findById(Integer id){
        Information id1 = iInformationService.getById(id);
        return Result.ok(id1);
    }

    //删除
    @PostMapping("/deleteById")
    public Result deleteById(@RequestBody Integer id) {
        boolean b = iInformationService.removeById(id);
        return Result.ok(b);
    }

    /**
     * 添加或修改
     */
    @PostMapping("/add")
    public Result saveOrUpdate(@RequestBody Information information) {
        boolean save = iInformationService.saveOrUpdate(information);
        return Result.ok(save);
    }


    /**
     * 批量删除
     */
    @PostMapping("/del/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        boolean id = iInformationService.removeByIds(ids);
        return Result.ok(id);
    }


}
